# coding: utf-8
# @Time    : 2020/8/25 10:06
# @Author  : gongshuangxi
# @Email   : sxgong@topdatasec.com

import os
import re
import sys
from Cython.Build import cythonize
from Cython.Compiler import Options
from distutils.core import Extension, setup

try:
    # python2
    reload(sys)
    sys.setdefaultencoding('utf-8')
except:
    # python3
    pass


# 过滤配置文件
exclude_so = ['__init__.py']
# 源码所在目录
sources = ['apps', 'libs', 'macro']

extensions = []
for source in sources:
    for dirpath, foldernames, filenames in os.walk(source):
        for filename in filter(lambda x: re.match('.*[.]py$', x), filenames):
            file_path = os.path.join(dirpath, filename)
            if filename not in exclude_so:
                extensions.append(
                    Extension(file_path[:-3].replace('/', '.'), [file_path],
                              extra_compile_args = ["-Os", "-g0", "-fPIC"],
                              extra_link_args=["-Wl,--strip-all"])
                )


Options.docstrings = False
compiler_directives = {'optimize.unpack_method_calls': False}


setup(
    ext_modules=cythonize(extensions, exclude=None, nthreads=20, quiet=True, build_dir="./build",
                          language_level=2, compiler_directives=compiler_directives)
)
